package _5_multithread._1_basic;

/**
 * Volatile 关键字不能保证原子性
 */
public class _1_VolatileNoSupportAutomatic {

  public volatile int a = 0;

  public void increase() {
    a++;
  }

  public static void main(String[] args) throws InterruptedException {
    final _1_VolatileNoSupportAutomatic volatileNoSupportAutomatic = new _1_VolatileNoSupportAutomatic();
    for (int i = 0; i < 10; i++) {
      new Thread(() -> {
        for (int j = 0; j < 1000; j++) {
          volatileNoSupportAutomatic.increase();
        }
      }).start();
    }
    Thread.sleep(60000);
    // while (Thread.activeCount() > 1) {
    //   Thread.yield();
    // }
    System.out.println(volatileNoSupportAutomatic.a);
  }

}
